#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N = 810, M = 3000, INF = 0x3f3f3f3f;
int h[N], ne[M], e[M], w[M], idx;
bool st[N];
int id[N], dist[N];
int n, p, m;
void add(int a, int b, int c)
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
int spfa(int start)
{
    memset(dist, 0x3f, sizeof dist);
    queue<int> q;
    q.push(start);
    dist[start] = 0;
    st[start] = true;
    while (q.size())
    {
        int t = q.front();
        q.pop();
        st[t] = false;
        for (int i = h[t]; ~i; i = ne[i])
        {
            int j = e[i];
            if (dist[j] > dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                if (st[j] == false)
                {
                    q.push(j);
                    st[j] = true;
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (dist[id[i]] == INF) return INF;
        else res += dist[id[i]];
    }
    return res;
}
int main()
{
    cin >> n >> p >> m;
    memset(h, -1, sizeof h);
    for (int i = 0; i < n; i++) cin >> id[i];
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        add(a, b, c), add(b, a, c);
    }
    int res = INF;
    for (int i = 1; i <= p; i++) res = min(res, spfa(i));
    cout << res << endl;
    return 0;
}